/*
 *
 * Copyright (C) 2012 Walter Lütgenau
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package offset.nodes.client.xpath.model;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import javax.jcr.PropertyType;

/**
 *
 * @author Walter Luetgenau
 */
public class PropertyTypeOperators {
    static HashMap<Integer,Operator[]> propertyTypeOperators = new HashMap<Integer,Operator[]>();
    static {
        propertyTypeOperators.put(new Integer(PropertyType.STRING), 
                new Operator[] {Operator.equal, Operator.notEqual, Operator.greater, Operator.greaterEqual, Operator.less, Operator.lessEqual, Operator.like, Operator.contains});
        propertyTypeOperators.put(new Integer(PropertyType.LONG), 
                new Operator[] {Operator.equal, Operator.notEqual, Operator.greater, Operator.greaterEqual, Operator.less, Operator.lessEqual});
        propertyTypeOperators.put(new Integer(PropertyType.DOUBLE), 
                new Operator[] {Operator.equal, Operator.notEqual, Operator.greater, Operator.greaterEqual, Operator.less, Operator.lessEqual});
        propertyTypeOperators.put(new Integer(PropertyType.DATE), 
                new Operator[] {Operator.equal, Operator.notEqual, Operator.greater, Operator.greaterEqual, Operator.less, Operator.lessEqual});
        propertyTypeOperators.put(new Integer(PropertyType.NAME), 
                new Operator[] {Operator.equal, Operator.notEqual});
        propertyTypeOperators.put(new Integer(PropertyType.PATH), 
                new Operator[] {Operator.equal, Operator.notEqual});
        propertyTypeOperators.put(new Integer(PropertyType.REFERENCE), 
                new Operator[] {Operator.equal, Operator.notEqual, Operator.deref});
        propertyTypeOperators.put(new Integer(PropertyType.BOOLEAN), 
                new Operator[] {Operator.equal, Operator.notEqual});
        propertyTypeOperators.put(new Integer(PropertyType.BINARY),
                new Operator[] {});
        propertyTypeOperators.put(new Integer(PropertyType.UNDEFINED),
                new Operator[] {});
    }
    
    /**
     * Return the operators possible for a given property type.
     * 
     * @param propertyType
     * @return the allowed operators.
     */
    public static Operator[] getOperators(int propertyType) {
        return propertyTypeOperators.get(new Integer(propertyType));
    }
}
